package com.ruoyi.auth.service;

import com.ruoyi.common.core.constant.SecurityConstants;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.core.model.LoginUser;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.miniapp.api.RemoteAppUserService;
import com.ruoyi.miniapp.api.domain.AppUser;

import org.springframework.stereotype.Component;

import javax.annotation.Resource;


@Component
public class AppLoginService {
    @Resource
    private RemoteAppUserService remoteAppUserService;

    public LoginUser<AppUser> login(String tel) {
        R<LoginUser<AppUser>> appUser = remoteAppUserService.getAppUserInfoByTel(tel, SecurityConstants.INNER);
        if (StringUtils.isNull(appUser) || StringUtils.isNull(appUser.getData())) {
            throw new ServiceException("登录用户：" + appUser.getData().getUsername() + " 不存在");
        }

        return appUser.getData();
    }

    public void logout(String loginName) {

    }

    public void register(String username, String password) {

    }
}
